//
//  SYZiYuanTopBackView.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/5/27.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "SYZiYuanTopBackView.h"


@interface SYZiYuanTopBackView ()

@property (strong, nonatomic) UIButton *backBtn;

@property (strong, nonatomic) NSString *titleName;
@property (strong, nonatomic) UIViewController *conView;
@property (strong, nonatomic) UIView *fgxView;

@end



@implementation SYZiYuanTopBackView

- (instancetype)initWithViewController:(UIViewController *)vc {
    self = [super init];
    if (self) {
        self.conView = vc;
        [self initSubView];
    }
    return self;
}


- (void)initSubView {
    [self addSubview:self.backBtn];
    [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY).offset(10);
        make.left.equalTo(self.mas_left).offset(20);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(40);
    }];
    [self addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self.mas_centerY).offset(10);
    }];
    self.titleLab.text = self.titleName;
    
    [self addSubview:self.fgxView];
    [self.fgxView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(20);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(1);
    }];
}

- (void)backBtnClick {
    if ([self.fromVC isEqualToString:@"chat"]) {
        if (self.backToVCClick) {
            self.backToVCClick();
        }
        
    }else{
        [self.conView dismissViewControllerAnimated:YES completion:nil];

    }
}

- (UIButton *)backBtn {
    if (!_backBtn) {
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [_backBtn setTitle:@" 返回" forState:UIControlStateNormal];
        [_backBtn setTitleColor:[UIColorChange colorwithHexString:@"SELECTEDCOLOR"] forState:UIControlStateNormal];
        [_backBtn setImage:[UIImage imageNamed:@"back_color"] forState:UIControlStateNormal];
        _backBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_backBtn setTitleColor:SELECTEDCOLOR forState:0];
        [_backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backBtn;
}
- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel titleColour:TITLECOLOR
                              titleFount:16
                                pingfang:@"PingFang-SC-Regular"
                               alignment:NSTextAlignmentCenter
                               titleLine:1];
    }
    return _titleLab;
}
- (UIView *)fgxView {
    if (!_fgxView) {
        _fgxView = [UIView new];
        _fgxView.backgroundColor = [UIColor colorWithHexString:@"#CCCCCC"];
    }
    return _fgxView;
}

@end
